package com.wsjzzcbq.qianyuan.common.service.impl;

import com.wsjzzcbq.qianyuan.common.service.FileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;

/**
 * LocalDrectoryFileServiceImpl 本地目录上传文件服务实现
 *
 * @author wsjz
 * @date 2022/03/14
 */
@Slf4j
@Service("localDrectoryFileServiceImpl")
public class LocalDrectoryFileServiceImpl implements FileService {

    @Value("${qianyuan.file.upload.path}")
    private String fileUploadPath;

    @Override
    public void upload(MultipartFile file, String fileName) {
        File newfile = new File(fileName);
        if (!newfile.getParentFile().exists()) {
            newfile.getParentFile().mkdirs();
        }
        try {
            file.transferTo(newfile);
        } catch (IOException e) {
            log.error("upload file exception", e);
        }
    }
}
